<template>
  <div class="siteAndRailWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">用户账户:</span>
                <span class="searchInputFont">
                    <el-input clearable size="mini" v-model="searchInfo.account" @change="searchRowsInfo(true)" auto-complete="off" placeholder="用户账户"></el-input>
                </span>
              </div>
            </el-col>
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">用户状态:</span>
                <span class="searchInputFont">
                    <el-select v-model="searchInfo.userStatus" @change="searchRowsInfo(true)" size="mini" clearable placeholder="用户状态">
                       <el-option
                         v-for="item in options"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
                        </el-option>
                    </el-select>
                </span>
              </div>
            </el-col>

            <div style="float: right;margin-right: 10px;">
              <el-button type="primary" size="mini" @click="searchRowsInfo()">查询</el-button>
              <addBtn v-if="$store.state.btnMenuIds.indexOf(133)>-1" :roleList="roleList" @searchRowsInfo="searchRowsInfo"></addBtn>
            </div>
          </el-row>
        </div>
      </div>
      <div class="tableContainer" >
        <div class="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="角色类型"
              prop="userType"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.userType == 1 ? "市交通局" : scope.row.userType == 2 ? "市交警局" : scope.row.userType == 3 ? "市城管局" : scope.row.userType == 4 ? "区政府" :"超级管理员"}}
              </template>
            </el-table-column>
            <el-table-column
              label="角色级别"
              prop="roleLevel"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.roleLevel == 1 ? "管理员" : scope.row.roleLevel == 2 ? "普通" :""}}
              </template>
            </el-table-column>
            <!--<el-table-column
              label="部门"
              prop="department"
              show-overflow-tooltip>
            </el-table-column>-->
            <el-table-column
              label="用户账户"
              prop="account"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="姓名"
              prop="userName"
              show-overflow-tooltip>

            </el-table-column>
            <el-table-column
              label="联系电话"
              prop="mobile"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="邮箱"
              prop="email"
              width="180"
              show-overflow-tooltip>
            </el-table-column>

            <el-table-column
              label="用户状态"
              prop="onlineStatus"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.userStatus == 1 ? "启用" :scope.row.userStatus == 2 ? "停用" : ""}}
              </template>
            </el-table-column>
            <el-table-column
              label="最后登录时间"
              prop="loginTime"
              width="140"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                {{scope.row.loginTime}}
              </template>
            </el-table-column>
            <el-table-column
              v-if="$store.state.btnMenuIds.indexOf(132)>-1"
              label="操作"
             >
              <template slot-scope="scope">
                <setBtn   :editInfo="scope.row" :roleList="roleList" @searchRowsInfo="searchRowsInfo" ></setBtn>
                <i @click="resetPass(scope.row)" class="iconfont icon-zhongzhimima" style="margin-left: 10px;"></i>
                <i @click='handleDelete(scope.row)' class="iconfont icon-shanchu" style="margin-left: 10px;"></i>
               </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="paginationWrap" >
          <el-row :gutter="10">
            <el-col :span="13" :offset="9">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 30, 50, 100,200]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="count">
              </el-pagination>
            </el-col>
          </el-row>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import addBtn from './addBtn.vue';
  import setBtn from './setBtn.vue';
  export default {
    props: [],
    data(){
      return {
        options: [
           {
            value: '1',
            label: '启用'
          }, {
            value: '2',
            label: '停用'
          }],
        options1: [
          {
            value: '1',
            label: '市交通局'
          }, {
            value: '2',
            label: '市交警局'
          }, {
            value: '3',
            label: '市城管局'
          }, {
            value: '4',
            label: '区政府'
          }],
        streetData: [],
        rows: [],
        pageSize: 10,
        count: 0,
        currentPage: 1,
        tableHeight: 400,
        checkInfo: {},
        roleList: [],
        searchInfo: {
          street: "",
          roleType: "",
          userType: "",
          userStatus: "",
          account: "",
          sortType: "",
          asc: "true"
        },
      }
    },
    components: {addBtn,setBtn},
    created(){
      //获取所有角色
      this.axios.post(process.env.API_HOST + `/system/selectSysRoleList`,{})
        .then(response => {
          const result = response.data
          if (result.code === 200) {
            this.roleList=result.result
          }
        })

      this.searchRowsInfo()
    },
    mounted(){
      this.$nextTick(() => {
        //表格高度
        this.tableHeight = document.querySelector(".siteAndRailWrap").clientHeight - 160
      })
    },

    methods: {
      resetPass(row){
        this.$confirm('确认重置用户 “' + row.userName + '” 的密码为 "Jgpt2020" ?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + '/system/updateSysUser',{...row,password:this.signPw("Jgpt2020")})
            .then(response => {
              if (response.data.code == 200) {
                this.$message({
                  type: 'success',
                  message: '重置成功!'
                });
              }

            })
            .catch(error => {
              console.log(error);
            });

          //删除当前
        }).catch(() => {

        });
      },
      pushAndGet(row){
        this.checkInfo=row
        this.$router.push("/parkingArea/parkSet")
      },
      handleDelete(row){
        this.$confirm('确认删除用户 “' + row.userName + '” , 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + `/system/deleteSysUser`,{sysUserId:row.sysUserId})
            .then(response => {
              const result = response.data
              if (result.code === 200) {
                this.searchRowsInfo()
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              }
            })

          //删除当前
        }).catch(() => {

        });
      },
      //获取街道
      changeDistrict(roleType){
        this.searchRowsInfo()
        this.axios.post(process.env.API_HOST + '/common/selectRegion',{parentId:roleType})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.streetData = result.result
            }
          })
      },
      //排序
      sortChange(a) {
        if (a.column) {
          if (a.column.label == "电子标签") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "labelNo"
            this.searchRowsInfo()
          } else if (a.column.label == "车辆编号") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "vehicleNo"
            this.searchRowsInfo()
          } else {
            this.searchInfo.sortType = a.prop
            this.searchRowsInfo()
          }
        } else {
          this.searchInfo.asc = "true", this.searchInfo.sortType = ""
        }
      },


      //获取所有信息
      searchRowsInfo(key){
        if(key){
          this.currentPage = 1;
        }
        this.axios.post(process.env.API_HOST + `/system/selectSysUserGrid`,{
          page: this.currentPage,
          rows: this.pageSize,
          account:this.searchInfo.account,
          userType:this.searchInfo.userType,
          street:this.searchInfo.street,
          userStatus:this.searchInfo.userStatus,
        })
          .then(response => {
            const result = response.data
            if(result.code==200){
              this.rows = result.rows
              this.count = result.total;
            }
          })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchRowsInfo()
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.searchRowsInfo()

      },
    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .siteAndRailWrap
    page()
</style>
